#include <GL/freeglut.h>
#include <iostream>

#include "main.h"
#include "Application.h"

#define TIMER_INTERVAL 20

// global app object
Application *app = new Application;

// Function prototypes for GLUT
void processRendering(void);
void processMouse(int, int) ;
void processMouseClick(int button, int state, int x, int y);
void keyboardInput(unsigned char c, int x, int y);
void processSpecialInput(int key, int x, int y);
void processSpecialInput(int key, int x, int y);
void processIdle(void);
void processClose(void);
void processTimer(int time);

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
	glutInitWindowPosition(100, 50);

	glutCreateWindow("Groundhog Game");
	glutDisplayFunc(processRendering);
	glutPassiveMotionFunc(processMouse);
	glutMotionFunc(processMouse);
	glutMouseFunc(processMouseClick);
	glutKeyboardFunc(keyboardInput);
	glutSpecialFunc(processSpecialInput);
	glutCloseFunc(processClose);
	glutIdleFunc(processIdle);
	glutTimerFunc(TIMER_INTERVAL, processTimer, 0);

	app->main(argc, argv);
	return 0;
}

void processRendering()
{
	app->ProcessRendering();
}

void processMouse(int x, int y)
{
    app->ProcessMouse(x, y);
}

void processMouseClick(int button, int state, int x, int y)
{
    app->ProcessMouseClick(button, state, x, y);
}

void keyboardInput(unsigned char c, int x, int y)
{
    app->KeyboardInput(c, x, y);
}

void processSpecialInput(int key, int x, int y)
{
	app->ProcessSpecialInput(key, x, y);
}

void processIdle(void)
{
	app->ProcessIdle();
}

void processClose(void)
{
	/*app->ProcessClose();
	delete app;*/
}

void processTimer(int time)
{
	glutPostRedisplay();
	glutTimerFunc(TIMER_INTERVAL, processTimer, 0);
}

GameManager *GetGameManager()
{
	return app->getGameMgr();
}

Application *GetApplication()
{
	return app;
}

WorldManager *GetWorldManager()
{
	return app->getWorldMgr();
}